<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Insert title here</title>

<link href="../bootstrap/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
html {
	padding: 10px 20px 10px 20px;
}
</style>
</head>
<body>
	<div class="panel panel-default">
		<div class="panel-heading">文章修改</div>
		<div class="panel-body">
			<form class="form-horizontal" action="edit.action" 
				method="post" enctype="multipart/form-data">
				
				<input type="hidden" name="id" value="${post.id }">
				
				<div class="form-group">
					<label for="title" class="col-sm-2 control-label">文章标题</label>
					<div class="col-sm-4">
						<input type="text" class="form-control" id="title" name="title" value="${post.title }">
					</div>
				</div>
				<div class="form-group">
					<label for="created" class="col-sm-2 control-label">创建时间</label>
					<div class="col-sm-4">
						<input type="text" class="form-control" id="created" name="created" 
							value='<fmt:formatDate value="${post.created }" pattern="yyyy-MM-dd HH:mm:ss"/>'>
					</div>
				</div>
				<div class="form-group">
					<label for="category" class="col-sm-2 control-label">文章分类</label>
					<div class="col-sm-2">
						<select class="form-control" id="category" name="category.id">
							<c:forEach items="${categories}" var="c">
								<!-- 
									if (post.category.id == c.id) {
										<option value="${c.id }" selected>${c.name }</option>
									} else {
										<option value="${c.id }">${c.name }</option>
									}
								 -->
								<c:choose>
									<c:when test="${post.category.id == c.id }">
										<option value="${c.id }" selected>${c.name }</option>
									</c:when>
									<c:otherwise>
										<option value="${c.id }">${c.name }</option>
									</c:otherwise>
								</c:choose>
							</c:forEach>
						</select>
					</div>
				</div>
				<div class="form-group">
					<label for="content" class="col-sm-2 control-label">文章内容</label>
					<div class="col-sm-10">
						<textarea class="form-control" id="content" rows="4" name="content">${post.content }</textarea>
					</div>
				</div>
				<div class="form-group">
					<label for="postImage" class="col-sm-2 control-label">文章封面</label>
					<div class="col-sm-10">
						<input type="file" name="uploadFile" class="form-control-file" id="postImage">
					</div>
				</div>

				<div class="form-group">
					<div class="col-sm-offset-2 col-sm-10">
						<button type="submit" class="btn btn-primary"
							style="width: 100px;">提交</button>
					</div>
				</div>
			</form>
		</div>
	</div>

	<script src="../js/jquery.min.js"></script>
	<script src="../bootstrap/bootstrap.min.js"></script>
</body>
</html>